package sort;

public class Dichotomy {
    public static void main(String[] args) {
        int[] ints = {50,8,75,54,78,24,64,99};
        sort(ints);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }

    public static void sort(int[] arr){
        int left,right,mid,temp;
        for (int i = 0; i < arr.length; i++) {
            left = 0;
            right = i-1;
            temp = arr[i];
            while (left <= right){
                mid = (left + right)/2;
                if (arr[mid] > temp){
                    right = mid -1;
                }else {
                    left = mid + 1;
                }
            }

            for (int j = i-1; j >= left; j--) {
                arr[j+1] = arr[j];
            }

            if(i!=left)
            {
                arr[left] = temp;
            }
        }
    }
}
